package com.itjeffrey.autocode.runner;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * CommandLineRunner与ApplicationRunner区别：接收的参数区别。
 *    CommandLineRunner的参数是最原始的参数，没有做任何处理。
 *    ApplicationRunner的参数是ApplicationArguments，是对原始参数做了进一步的封装。
 *    ApplicationArguments是对(main方法)参数做了进一步的处理，可以解析--name=value的，
 *    我们就可以通过name来获取value（而CommandLineRunner只是获取--name=value）
 *
 * notes: 默认加载顺序 ApplicationRunner > CommandLineRunner (ApplicationRunner与CommandLineRunner均不设置@Order前提下)
 */
//@Order(value = 0)
@Component
public class MyApplicationRunner implements ApplicationRunner {

    /**
     * MyApplicationRunner run
     * @param args SpringBoot Environment Program arguments
     *             eg: --project=autocode --developer=jeffrey
     * @throws Exception
     */
    @Override
    public void run(ApplicationArguments args) throws Exception {
        //Return the raw unprocessed arguments that were passed to the application
        System.out.println("===MyApplicationRunner==="+ Arrays.asList(args.getSourceArgs()));
        //Return the names of all option arguments
        System.out.println("===getOptionNames========"+args.getOptionNames());
        //Return the collection of values associated with the arguments option having the given name
        System.out.println("===getOptionValues======="+args.getOptionValues("project"));
        System.out.println("===getOptionValues======="+args.getOptionValues("developer"));
    }

}
